package com.dm.db.mysql;

import com.alibaba.druid.pool.DruidDataSource;
import com.dm.db.FetchDatabase;
import com.dm.db.condition.MysqlCondition;
import com.dm.mapper.MysqlSystemMapper;
import com.dm.pojo.db.Database;
import com.dm.pojo.db.Field;
import com.dm.pojo.db.Table;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;


@Component
@Conditional(MysqlCondition.class)
public class FeignDataBaseMysql implements FetchDatabase {

    @Resource
    private MysqlSystemMapper mysqlSystemMapper;

    @Override
    public List<Database> fetchDatabase(DruidDataSource druidDataSource) {
        return mysqlSystemMapper.fetchDatabase();
    }

    @Override
    public List<Table> fetchTable(Database database) {
        return mysqlSystemMapper.fetchTable(database);
    }

    @Override
    public List<Field> fetchField(Database database,Table table) {
        return mysqlSystemMapper.fetchField(database.getName(),table.getTableName());
    }
}
